//
//  GRSotreCommentTableViewCell.m
//  YC_GRice
//
//  Created by luojinrong11 on 2018/8/24.
//  Copyright © 2018年 YeCai. All rights reserved.
//

#import "GRSotreCommentTableViewCell.h"
#import "GRPhotoImageCell.h"
@implementation GRSotreCommentTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.photoList.delegate = self;
    self.photoList.dataSource = self;
    [self.photoList registerNib:[UINib nibWithNibName:@"GRPhotoImageCell" bundle:[NSBundle mainBundle]] forCellWithReuseIdentifier:@"imageCell"];
    // Initialization code
}

-(void)setCommentModel:(GRStoreCommentModel *)commentModel{
    _commentModel = commentModel;
    [self.headImageView sd_setImageWithURL:[NSURL URLWithString:commentModel.avatar]];
    self.content.text = commentModel.content;
    self.nickNameLabel.text = commentModel.nickname;
    self.timeLabel.text = commentModel.createAt;
    self.replyContent.text = commentModel.replyContent;
    NSInteger yu = commentModel.photosArray.count%3;
    NSInteger count = yu >=1 ?(commentModel.photosArray.count/3)+1:commentModel.photosArray.count/3;
    CGFloat  height = count *((KscreenWidth-90)/3)+(count -1)*8;
    self.photoHeight.constant = height;
    self.replyContent.hidden = commentModel.replyContent.length >0 ?NO:YES;
    self.photoList.hidden = commentModel.photosArray.count >0?NO:YES;
    self.replyView.hidden = commentModel.replyContent.length >0 ?NO:YES;;
    [self.photoList reloadData];
}

-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    GRPhotoImageCell * cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"imageCell" forIndexPath:indexPath];
    [cell.photoImageView sd_setImageWithURL:self.commentModel.photosArray[indexPath.row]];
    return cell;
    
}

-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{
    return self.commentModel.photosArray.count;
}

-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    
}

-(CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath{
    return CGSizeMake((KscreenWidth-90)/3, (KscreenWidth-90)/3);
}
-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumLineSpacingForSectionAtIndex:(NSInteger)section{
    return 10;
}

-(CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section{
    return 10;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
